import 'package:aidou/style/style.dart';
import 'package:flutter/material.dart';

class VideoPlayerItem extends StatelessWidget {
  final Widget? video;
  final double aspectRatio;
  final String? tag;
  final double bottomPadding;

  final Widget? rightButtonColumn;
  final Widget? userInfoWidget;

  final bool hidePauseIcon;

  final Function? onSingleTap;

  const VideoPlayerItem({
    Key? key,
    this.bottomPadding: 16,
    this.video,
    this.aspectRatio: 9 / 16.0,
    this.tag,
    this.rightButtonColumn,
    this.userInfoWidget,
    this.onSingleTap,
    this.hidePauseIcon: false,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // 右边的按钮列表
    Widget rightButtons = rightButtonColumn ?? Container();
    // 用户信息
    Widget userInfo = userInfoWidget ??
        VideoInfo(
          bottomPadding: bottomPadding,
        );
    // 视频播放部件
    Widget videoContainer = GestureDetector(
      onTap: () {
        onSingleTap?.call();
      },
      child: Stack(
        children: <Widget>[
          Container(
            width: double.infinity,
            height: double.infinity,
            color: Colors.black,
            child: FittedBox(
              // 等比铺满页面
              fit: BoxFit.cover,
              alignment: Alignment.center,
              child: Container(
                // 宽高按照 aspectRatio 9 / 16.0设置，目前暂时写死的
                width: 450,
                height: 800,
                child: video,
              ),
            ),
          ),
          hidePauseIcon
              ? Container(
                  height: double.infinity,
                  width: double.infinity,
                  alignment: Alignment.center,
                  child: Icon(
                    Icons.play_circle_outline,
                    size: 100,
                    color: Colors.white.withOpacity(0.4),
                  ),
                )
              : Container()
        ],
      ),
    );
    Widget body = Container(
      child: Stack(
        children: <Widget>[
          videoContainer,
          Container(
            height: double.infinity,
            width: double.infinity,
            alignment: Alignment.bottomRight,
            child: rightButtons,
          ),
          Container(
            height: double.infinity,
            width: double.infinity,
            alignment: Alignment.bottomLeft,
            child: userInfo,
          ),
        ],
      ),
    );
    return body;
  }
}

// 视频信息
class VideoInfo extends StatelessWidget {
  final String? title;
  final String? nickName;
  const VideoInfo({
    Key? key,
    required this.bottomPadding,
    this.title,
    this.nickName,
  }) : super(key: key);

  final double bottomPadding;

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(
        left: 12,
        bottom: bottomPadding,
      ),
      margin: EdgeInsets.only(right: 60),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.end,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text(
            nickName ?? '小艾豆',
            style: StandardTextStyle.big,
          ),
          Container(height: 6),
          Text(
            title ?? '#原创 无趣的BUG #艾逗短视频',
            maxLines: 9,
            style: StandardTextStyle.normal,
          ),
        ],
      ),
    );
  }
}
